using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
using System.Web;
using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeImageAnnotation_ImageAnnotation"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class ImageAnnotation : Annotation
	{
		private string _imageName = string.Empty;
		private Color _imageTransparentColor = Color.Empty;
		private ChartImageWrapMode _imageWrapMode = ChartImageWrapMode.Scaled;

		internal override RectangleF GetContentPosition()
		{
			if (this.Image.Length > 0)
			{
				try
				{
					if (base.Chart != null)
					{
						ImageLoader imageLoader = base.Common.ImageLoader;
						if (imageLoader != null)
						{
							ChartGraphics graphics = base.GetGraphics();
							if (graphics != null)
							{
								SizeF size = new SizeF();
								if (imageLoader.GetAdjustedImageSize(this.Image, graphics.Graphics, ref size))
								{
									SizeF relativeSize = graphics.GetRelativeSize(size);
									return new RectangleF(float.NaN, float.NaN, relativeSize.Width, relativeSize.Height);
								}
							}
						}
					}
				}
				catch (ArgumentException)
				{
				}
			}
			return new RectangleF(float.NaN, float.NaN, float.NaN, float.NaN);
		}

		private ChartImageAlignmentStyle GetImageAlignment(ContentAlignment alignment)
		{
			if (alignment == ContentAlignment.TopLeft)
			{
				return ChartImageAlignmentStyle.TopLeft;
			}
			if (alignment == ContentAlignment.TopCenter)
			{
				return ChartImageAlignmentStyle.Top;
			}
			if (alignment == ContentAlignment.TopRight)
			{
				return ChartImageAlignmentStyle.TopRight;
			}
			if (alignment == ContentAlignment.MiddleRight)
			{
				return ChartImageAlignmentStyle.Right;
			}
			if (alignment == ContentAlignment.BottomRight)
			{
				return ChartImageAlignmentStyle.BottomRight;
			}
			if (alignment == ContentAlignment.BottomCenter)
			{
				return ChartImageAlignmentStyle.Bottom;
			}
			if (alignment == ContentAlignment.BottomLeft)
			{
				return ChartImageAlignmentStyle.BottomLeft;
			}
			if (alignment == ContentAlignment.MiddleLeft)
			{
				return ChartImageAlignmentStyle.Left;
			}
			return ChartImageAlignmentStyle.Center;
		}

		internal override void Paint(Chart chart, ChartGraphics graphics)
		{
			PointF empty = PointF.Empty;
			PointF anchorLocation = PointF.Empty;
			SizeF size = SizeF.Empty;
			this.GetRelativePosition(out empty, out size, out anchorLocation);
			PointF tf3 = new PointF(empty.X + size.Width, empty.Y + size.Height);
			RectangleF rect = new RectangleF(empty, new SizeF(tf3.X - empty.X, tf3.Y - empty.Y));
			RectangleF rectF = new RectangleF(rect.Location, rect.Size);
			if (rectF.Width < 0f)
			{
				rectF.X = rectF.Right;
				rectF.Width = -rectF.Width;
			}
			if (rectF.Height < 0f)
			{
				rectF.Y = rectF.Bottom;
				rectF.Height = -rectF.Height;
			}
			if ((float.IsNaN(rectF.X) || float.IsNaN(rectF.Y)) || (float.IsNaN(rectF.Right) || float.IsNaN(rectF.Bottom)))
			{
				return;
			}
			if (base.Common.ProcessModePaint)
			{
				if ((this._imageName.Length == 0) && base.Chart.IsDesignMode())
				{
					graphics.FillRectangleRel(rectF, this.BackColor, this.BackHatchStyle, this._imageName, this._imageWrapMode, this._imageTransparentColor, this.GetImageAlignment(this.Alignment), this.BackGradientStyle, this.BackSecondaryColor, this.LineColor, this.LineWidth, this.LineDashStyle, this.ShadowColor, this.ShadowOffset, PenAlignment.Center);
					using (Brush brush = new SolidBrush(this.ForeColor))
					{
						using (StringFormat format = new StringFormat(StringFormat.GenericTypographic))
						{
							format.Alignment = StringAlignment.Center;
							format.LineAlignment = StringAlignment.Center;
							format.FormatFlags = StringFormatFlags.LineLimit;
							format.Trimming = StringTrimming.EllipsisCharacter;
							graphics.DrawStringRel("(no image)", this.Font, brush, rectF, format);
						}
						goto Label_0264;
					}
				}
				graphics.FillRectangleRel(rectF, Color.Transparent, this.BackHatchStyle, this._imageName, this._imageWrapMode, this._imageTransparentColor, this.GetImageAlignment(this.Alignment), this.BackGradientStyle, Color.Transparent, Color.Transparent, 0, this.LineDashStyle, this.ShadowColor, this.ShadowOffset, PenAlignment.Center);
			}
		Label_0264:
			if (base.Common.ProcessModeRegions)
			{
				base.Common.HotRegionsList.AddHotRegion(rectF, base.ReplaceKeywords(this.ToolTip), base.ReplaceKeywords(this.Url), base.ReplaceKeywords(this.MapAreaAttributes), base.ReplaceKeywords(base.PostBackValue), this, ChartElementType.Annotation, string.Empty);
			}
			this.PaintSelectionHandles(graphics, rect, null);
		}

		[SRCategory("CategoryAttributeImage"), SRDescription("DescriptionAttributeImageAnnotation_Alignment"), DefaultValue(typeof(ContentAlignment), "MiddleCenter")]
		public override ContentAlignment Alignment
		{
			get
			{
				return base.Alignment;
			}
			set
			{
				base.Alignment = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeMisc"), Bindable(true), Browsable(false), SRDescription("DescriptionAttributeAnnotationType"), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden)]
		public override string AnnotationType
		{
			get
			{
				return "Image";
			}
		}

		[SRCategory("CategoryAttributeAppearance"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), Browsable(false), DefaultValue(typeof(Color), ""), NotifyParentProperty(true), TypeConverter(typeof(ColorConverter))]
		public override Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
			}
		}

		[Editor(typeof(GradientEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(0), NotifyParentProperty(true)]
		public override GradientStyle BackGradientStyle
		{
			get
			{
				return base.BackGradientStyle;
			}
			set
			{
				base.BackGradientStyle = value;
			}
		}

		[DefaultValue(0), SRCategory("CategoryAttributeAppearance"), Browsable(false), NotifyParentProperty(true), Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))]
		public override ChartHatchStyle BackHatchStyle
		{
			get
			{
				return base.BackHatchStyle;
			}
			set
			{
				base.BackHatchStyle = value;
			}
		}

		[DefaultValue(typeof(Color), ""), SRCategory("CategoryAttributeAppearance"), Browsable(false), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), NotifyParentProperty(true), TypeConverter(typeof(ColorConverter))]
		public override Color BackSecondaryColor
		{
			get
			{
				return base.BackSecondaryColor;
			}
			set
			{
				base.BackSecondaryColor = value;
			}
		}

		[Browsable(false), SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(System.Drawing.Font), "Microsoft Sans Serif, 8pt")]
		public override System.Drawing.Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(typeof(Color), "Black")]
		public override Color ForeColor
		{
			get
			{
				return base.ForeColor;
			}
			set
			{
				base.ForeColor = value;
			}
		}

		[Bindable(true), DefaultValue(""), SRDescription("DescriptionAttributeImageAnnotation_Image"), Editor(typeof(ImageValueEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeImage")]
		public virtual string Image
		{
			get
			{
				return this._imageName;
			}
			set
			{
				this._imageName = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(Color), ""), Bindable(true), SRCategory("CategoryAttributeImage"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributeImageTransparentColor")]
		public Color ImageTransparentColor
		{
			get
			{
				return this._imageTransparentColor;
			}
			set
			{
				this._imageTransparentColor = value;
				this.Invalidate();
			}
		}

		[DefaultValue(4), SRDescription("DescriptionAttributeImageWrapMode"), Bindable(true), SRCategory("CategoryAttributeImage")]
		public ChartImageWrapMode ImageWrapMode
		{
			get
			{
				return this._imageWrapMode;
			}
			set
			{
				this._imageWrapMode = value;
				this.Invalidate();
			}
		}

		[SRCategory("CategoryAttributeAppearance"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), Browsable(false), DefaultValue(typeof(Color), "Black"), TypeConverter(typeof(ColorConverter))]
		public override Color LineColor
		{
			get
			{
				return base.LineColor;
			}
			set
			{
				base.LineColor = value;
			}
		}

		[Browsable(false), SRDescription("DescriptionAttributeLineDashStyle"), SRCategory("CategoryAttributeAppearance"), DefaultValue(5)]
		public override ChartDashStyle LineDashStyle
		{
			get
			{
				return base.LineDashStyle;
			}
			set
			{
				base.LineDashStyle = value;
			}
		}

		[Browsable(false), DefaultValue(1), SRDescription("DescriptionAttributeLineWidth"), SRCategory("CategoryAttributeAppearance")]
		public override int LineWidth
		{
			get
			{
				return base.LineWidth;
			}
			set
			{
				base.LineWidth = value;
			}
		}

		[SRDescription("DescriptionAttributeSelectionPointsStyle"), ParenthesizePropertyName(true), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden), Browsable(false), SRCategory("CategoryAttributeAppearance"), DefaultValue(1)]
		internal override SelectionPointsStyle SelectionPointsStyle
		{
			get
			{
				return SelectionPointsStyle.Rectangle;
			}
		}

		[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
		public override TextStyle TextStyle
		{
			get
			{
				return base.TextStyle;
			}
			set
			{
				base.TextStyle = value;
			}
		}
	}
}

